package org.mycompany.resolver;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import org.mycompany.annotation.Column;

public class AnnotationResolver {

	private final static ClassLoader classLoader = AnnotationResolver.class
			.getClassLoader();

	public List<String> resolveColumns(String clazz) {
		final List<String> result = new ArrayList<String>();
		try {
			final Class<?> aClass = classLoader.loadClass(clazz);
			final Field[] fields = aClass.getDeclaredFields();
			for (int i = 0; i < fields.length; i++) {
				final Field field = fields[i];
				final Annotation annotion = field.getAnnotation(Column.class);
				if (annotion instanceof Column) {
					result.add(field.getName());
				}
			}
		} catch (final Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
}
